package com.dragee.modules.work.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dragee.config.exception.BusinessException;
import com.dragee.modules.exportEntity.*;
import com.dragee.modules.work.dto.TeamPerson;
import com.dragee.modules.work.entity.ApplyEntity;
import com.dragee.modules.work.entity.ApplyProjectEntity;
import com.dragee.modules.work.entity.ApplyScoreEntity;
import com.dragee.modules.work.entity.CompetitionOrderEntity;
import com.dragee.modules.work.service.*;
import com.dragee.utils.excel.ExcelUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author tys on 2023/8/10
 */
@RestController
@RequestMapping("work/scoreExport")
@Api(tags = "work - 排名导出")
public class ScoreExportController {
    @Autowired
    private CompetitionService competitionService;
    @Autowired
    private CompetitionProjectService competitionProjectService;
    @Autowired
    private ApplyService applyService;
    @Autowired
    private CompetitionOrderService competitionOrderService;
    @Autowired
    private ApplyProjectService applyProjectService;
    @Autowired
    private TeamService teamService;
    @Autowired
    private ApplyScoreService applyScoreService;

    @ApiOperation(value = "teamScoreJingji")
    @GetMapping("/teamScoreJingji")
    public void teamScoreJingji(String competitionId, String projectId , String type, String group,
                                HttpServletResponse response) throws Exception {
        if (StrUtil.isBlank(competitionId) || StrUtil.isBlank(competitionId) || StrUtil.isBlank(competitionId) || StrUtil.isBlank(competitionId)) {
            throw new BusinessException("查询条件缺失");
        }
        // 基础数据
        List<ApplyProjectEntity> datas = applyProjectService.list(new QueryWrapper<ApplyProjectEntity>()
                .eq("competitionId", competitionId)
                .eq("projectId", projectId)
                .eq("type", type)
                .eq("groups", group)
                .orderByDesc("sort"));
        List<ScoreTeamJingJiExport> results = new ArrayList<>();
        List<ScoreTeamJingJiExport> noNeedSortResult = new ArrayList<>();
        for (ApplyProjectEntity data : datas) {
            ScoreTeamJingJiExport ex = new ScoreTeamJingJiExport();
            ApplyProjectEntity applyProject = applyService.getApplyProjectInfo(data.getId().toString());
            ApplyEntity apply = applyService.getApplyInfo(applyProject.getApplyId());
            CompetitionOrderEntity order = competitionOrderService.getById(data.getOrderId());
            if (order != null) {
                ex.setOrder(order.getTitle());
                ex.setTime(DateUtil.format(order.getStartTime(), "yyyy-MM-dd HH:mm:ss"));
            }
            ex.setTeam(apply.getTeamName());
            List<TeamPerson> coachs = apply.getCoachs();
            String coachNames = ArrayUtil.join(coachs.stream().map(TeamPerson::getName).toArray(), ", ");
            List<TeamPerson> leaders = apply.getLeaders();
            String leaderNames = ArrayUtil.join(leaders.stream().map(TeamPerson::getName).toArray(), ", ");
            ex.setLeader(leaderNames);
            ex.setCoach(coachNames);
            ex.setProject(applyProject.getProjectName());
            ex.setType(applyProject.getType());
            ex.setGroups(applyProject.getGroups());
            ex.setAthletes(ArrayUtil.join(applyProject.getAthletes().stream().map(TeamPerson::getName).toArray(), ", "));
            ex.setCompetition(apply.getCompetitionName());
            ex.setStatus(applyProject.getStatus());
            if (!"打分结束".equals(ex.getStatus())) {
                noNeedSortResult.add(ex);
            } else {
                // 设置裁判分数
                List<ApplyScoreEntity> socres = applyScoreService.list(new QueryWrapper<ApplyScoreEntity>()
                        .eq("orderId", data.getOrderId())
                        .eq("applyProjectId", applyProject.getId())
                        .eq("status", "已打分")
                        .orderByDesc("sort"));
                if (socres.size() > 0) {
                    List<ApplyScoreEntity> yishus = socres.stream().filter(t -> "艺术裁判".equals(t.getType())).collect(Collectors.toList());
                    for (int i = 1; i <= yishus.size(); i++) {
                        ApplyScoreEntity score = yishus.get(i-1);
                        if (i == 1) {
                            ex.setOneReferee1(score.getScore().toString());
                        } else if (i == 2) {
                            ex.setOneReferee2(score.getScore().toString());
                        } else if (i == 3) {
                            ex.setOneReferee3(score.getScore().toString());
                        } else if (i == 4) {
                            ex.setOneReferee4(score.getScore().toString());
                        }
                    }

                    List<ApplyScoreEntity> wanchengs = socres.stream().filter(t -> "完成裁判".equals(t.getType())).collect(Collectors.toList());
                    for (int i = 1; i <= wanchengs.size(); i++) {
                        ApplyScoreEntity score = wanchengs.get(i-1);
                        if (i == 1) {
                            ex.setTwoReferee1(score.getScore().toString());
                        } else if (i == 2) {
                            ex.setTwoReferee2(score.getScore().toString());
                        } else if (i == 3) {
                            ex.setTwoReferee3(score.getScore().toString());
                        } else if (i == 4) {
                            ex.setTwoReferee4(score.getScore().toString());
                        }
                    }

                    List<ApplyScoreEntity> nandus = socres.stream().filter(t -> "难度裁判".equals(t.getType())).collect(Collectors.toList());
                    for (int i = 1; i <= nandus.size(); i++) {
                        ApplyScoreEntity score = nandus.get(i-1);
                        if (i == 1) {
                            ex.setThreeReferee1(score.getScore().toString());
                            ex.setNanDuJianFen1(score.getSubScore().toString());
                        } else if (i == 2) {
                            ex.setThreeReferee2(score.getScore().toString());
                            ex.setNanDuJianFen2(score.getSubScore().toString());
                        }
                    }
                    List<ApplyScoreEntity> caipanzhang = socres.stream().filter(t -> "裁判长".equals(t.getType())).collect(Collectors.toList());
                    if (caipanzhang.size() > 0) {
                        ApplyScoreEntity score = caipanzhang.get(0);
                        ex.setScore(score.getScore().toString());
                        ex.setCaiPanZhangJianFen(score.getReduceScore().toString());
                        ex.setSightScore(score.getSightScore() == null ? "0.00" : score.getSightScore().toString());
                    }
                }
                results.add(ex);
            }
        }
        // 排序
        results = results.stream().sorted((o2, o1) -> {
            return (StrUtil.isBlank(o1.getScore()) ? BigDecimal.ZERO : new BigDecimal(o1.getScore()))
                    .compareTo((StrUtil.isBlank(o2.getScore()) ? BigDecimal.ZERO : new BigDecimal(o2.getScore())));
        }).collect(Collectors.toList());
        // 排名
        BigDecimal nowScore = BigDecimal.ZERO;
        int sort = 1;
        for (int i = 0; i < results.size(); i++) {
            ScoreTeamJingJiExport data = results.get(i);
            if (i == 0) {
                nowScore = StrUtil.isBlank(data.getScore()) ? BigDecimal.ZERO : new BigDecimal(data.getScore());
                sort = 1;
                data.setScoreSort("第"+sort+"名");
            } else {
                BigDecimal myScore = StrUtil.isBlank(data.getScore()) ? BigDecimal.ZERO : new BigDecimal(data.getScore());
                if (myScore.compareTo(nowScore) == 0) {
                    data.setScoreSort("第"+sort+"名");
                } else {
                    sort++;
                    nowScore = myScore;
                    data.setScoreSort("第"+sort+"名");
                }
            }
        }
        // 加入不需要排名的数据
        results.addAll(noNeedSortResult);
        ExcelUtils.writeExcel(response,
                results,"队伍成绩单-竞技项目",
                "数据", ScoreTeamJingJiExport.class);
    }



    @ApiOperation(value = "teamScoreJianShenCao")
    @GetMapping("/teamScoreJianShenCao")
    public void teamScoreJianShenCao(String competitionId, String projectId , String type, String group,
                                HttpServletResponse response) throws Exception {
        if (StrUtil.isBlank(competitionId) || StrUtil.isBlank(competitionId) || StrUtil.isBlank(competitionId) || StrUtil.isBlank(competitionId)) {
            throw new BusinessException("查询条件缺失");
        }
        // 基础数据
        List<ApplyProjectEntity> datas = applyProjectService.list(new QueryWrapper<ApplyProjectEntity>()
                .eq("competitionId", competitionId)
                .eq("projectId", projectId)
                .eq("type", type)
                .eq("groups", group)
                .orderByDesc("sort"));
        List<ScoreTeamJianShenCaoExport> results = new ArrayList<>();
        List<ScoreTeamJianShenCaoExport> noNeedSortResult = new ArrayList<>();
        for (ApplyProjectEntity data : datas) {
            ScoreTeamJianShenCaoExport ex = new ScoreTeamJianShenCaoExport();
            ApplyProjectEntity applyProject = applyService.getApplyProjectInfo(data.getId().toString());
            ApplyEntity apply = applyService.getApplyInfo(applyProject.getApplyId());
            CompetitionOrderEntity order = competitionOrderService.getById(data.getOrderId());
            if (order != null) {
                ex.setOrder(order.getTitle());
                ex.setTime(DateUtil.format(order.getStartTime(), "yyyy-MM-dd HH:mm:ss"));
            }
            ex.setTeam(apply.getTeamName());
            List<TeamPerson> coachs = apply.getCoachs();
            String coachNames = ArrayUtil.join(coachs.stream().map(TeamPerson::getName).toArray(), ", ");
            List<TeamPerson> leaders = apply.getLeaders();
            String leaderNames = ArrayUtil.join(leaders.stream().map(TeamPerson::getName).toArray(), ", ");
            ex.setLeader(leaderNames);
            ex.setCoach(coachNames);
            ex.setProject(applyProject.getProjectName());
            ex.setType(applyProject.getType());
            ex.setGroups(applyProject.getGroups());
            ex.setAthletes(ArrayUtil.join(applyProject.getAthletes().stream().map(TeamPerson::getName).toArray(), ", "));
            ex.setCompetition(apply.getCompetitionName());
            ex.setStatus(applyProject.getStatus());
            if (!"打分结束".equals(ex.getStatus())) {
                noNeedSortResult.add(ex);
            } else {
                // 设置裁判分数
                List<ApplyScoreEntity> socres = applyScoreService.list(new QueryWrapper<ApplyScoreEntity>()
                        .eq("orderId", data.getOrderId())
                        .eq("applyProjectId", applyProject.getId())
                        .eq("status", "已打分")
                        .orderByDesc("sort"));
                if (socres.size() > 0) {
                    List<ApplyScoreEntity> yishus = socres.stream().filter(t -> "艺术裁判".equals(t.getType())).collect(Collectors.toList());
                    for (int i = 1; i <= yishus.size(); i++) {
                        ApplyScoreEntity score = yishus.get(i-1);
                        if (i == 1) {
                            ex.setOneReferee1(score.getScore().toString());
                        } else if (i == 2) {
                            ex.setOneReferee2(score.getScore().toString());
                        } else if (i == 3) {
                            ex.setOneReferee3(score.getScore().toString());
                        } else if (i == 4) {
                            ex.setOneReferee4(score.getScore().toString());
                        }
                    }

                    List<ApplyScoreEntity> wanchengs = socres.stream().filter(t -> "完成裁判".equals(t.getType())).collect(Collectors.toList());
                    for (int i = 1; i <= wanchengs.size(); i++) {
                        ApplyScoreEntity score = wanchengs.get(i-1);
                        if (i == 1) {
                            ex.setTwoReferee1(score.getScore().toString());
                        } else if (i == 2) {
                            ex.setTwoReferee2(score.getScore().toString());
                        } else if (i == 3) {
                            ex.setTwoReferee3(score.getScore().toString());
                        } else if (i == 4) {
                            ex.setTwoReferee4(score.getScore().toString());
                        }
                    }

                    List<ApplyScoreEntity> caipanzhang = socres.stream().filter(t -> "裁判长".equals(t.getType())).collect(Collectors.toList());
                    if (caipanzhang.size() > 0) {
                        ApplyScoreEntity score = caipanzhang.get(0);
                        ex.setScore(score.getScore().toString());
                        ex.setCaiPanZhangJianFen(score.getReduceScore().toString());
                        ex.setSightScore(score.getSightScore() == null ? "0.00" : score.getSightScore().toString());
                    }
                }
                results.add(ex);
            }
        }
        // 排序
        results = results.stream().sorted((o2, o1) -> {
            return (StrUtil.isBlank(o1.getScore()) ? BigDecimal.ZERO : new BigDecimal(o1.getScore()))
                    .compareTo((StrUtil.isBlank(o2.getScore()) ? BigDecimal.ZERO : new BigDecimal(o2.getScore())));
        }).collect(Collectors.toList());
        // 排名
        BigDecimal nowScore = BigDecimal.ZERO;
        int sort = 1;
        for (int i = 0; i < results.size(); i++) {
            ScoreTeamJianShenCaoExport data = results.get(i);
            if (i == 0) {
                nowScore = StrUtil.isBlank(data.getScore()) ? BigDecimal.ZERO : new BigDecimal(data.getScore());
                sort = 1;
                data.setScoreSort("第"+sort+"名");
            } else {
                BigDecimal myScore = StrUtil.isBlank(data.getScore()) ? BigDecimal.ZERO : new BigDecimal(data.getScore());
                if (myScore.compareTo(nowScore) == 0) {
                    data.setScoreSort("第"+sort+"名");
                } else {
                    sort++;
                    nowScore = myScore;
                    data.setScoreSort("第"+sort+"名");
                }
            }
        }
        // 加入不需要排名的数据
        results.addAll(noNeedSortResult);
        ExcelUtils.writeExcel(response,
                results,"队伍成绩单-健身操舞项目",
                "数据", ScoreTeamJianShenCaoExport.class);
    }


    @ApiOperation(value = "teamScorelalaCao")
    @GetMapping("/teamScorelalaCao")
    public void teamScorelalaCao(String competitionId, String projectId , String type, String group,
                                     HttpServletResponse response) throws Exception {
        if (StrUtil.isBlank(competitionId) || StrUtil.isBlank(competitionId) || StrUtil.isBlank(competitionId) || StrUtil.isBlank(competitionId)) {
            throw new BusinessException("查询条件缺失");
        }
        // 基础数据
        List<ApplyProjectEntity> datas = applyProjectService.list(new QueryWrapper<ApplyProjectEntity>()
                .eq("competitionId", competitionId)
                .eq("projectId", projectId)
                .eq("type", type)
                .eq("groups", group)
                .orderByDesc("sort"));
        List<ScoreTeamLaLaCaoExport> results = new ArrayList<>();
        List<ScoreTeamLaLaCaoExport> noNeedSortResult = new ArrayList<>();
        for (ApplyProjectEntity data : datas) {
            ScoreTeamLaLaCaoExport ex = new ScoreTeamLaLaCaoExport();
            ApplyProjectEntity applyProject = applyService.getApplyProjectInfo(data.getId().toString());
            ApplyEntity apply = applyService.getApplyInfo(applyProject.getApplyId());
            CompetitionOrderEntity order = competitionOrderService.getById(data.getOrderId());
            if (order != null) {
                ex.setOrder(order.getTitle());
                ex.setTime(DateUtil.format(order.getStartTime(), "yyyy-MM-dd HH:mm:ss"));
            }
            ex.setTeam(apply.getTeamName());
            List<TeamPerson> coachs = apply.getCoachs();
            String coachNames = ArrayUtil.join(coachs.stream().map(TeamPerson::getName).toArray(), ", ");
            List<TeamPerson> leaders = apply.getLeaders();
            String leaderNames = ArrayUtil.join(leaders.stream().map(TeamPerson::getName).toArray(), ", ");
            ex.setLeader(leaderNames);
            ex.setCoach(coachNames);
            ex.setProject(applyProject.getProjectName());
            ex.setType(applyProject.getType());
            ex.setGroups(applyProject.getGroups());
            ex.setAthletes(ArrayUtil.join(applyProject.getAthletes().stream().map(TeamPerson::getName).toArray(), ", "));
            ex.setCompetition(apply.getCompetitionName());
            ex.setStatus(applyProject.getStatus());
            if (!"打分结束".equals(ex.getStatus())) {
                noNeedSortResult.add(ex);
            } else {
                // 设置裁判分数
                List<ApplyScoreEntity> socres = applyScoreService.list(new QueryWrapper<ApplyScoreEntity>()
                        .eq("orderId", data.getOrderId())
                        .eq("applyProjectId", applyProject.getId())
                        .eq("status", "已打分")
                        .orderByDesc("sort"));
                if (socres.size() > 0) {
                    List<ApplyScoreEntity> yishus = socres.stream().filter(t -> "普通裁判".equals(t.getType())).collect(Collectors.toList());
                    for (int i = 1; i <= yishus.size(); i++) {
                        ApplyScoreEntity score = yishus.get(i-1);
                        if (i == 1) {
                            ex.setReferee1(score.getScore().toString());
                        } else if (i == 2) {
                            ex.setReferee2(score.getScore().toString());
                        } else if (i == 3) {
                            ex.setReferee3(score.getScore().toString());
                        } else if (i == 4) {
                            ex.setReferee4(score.getScore().toString());
                        } else if (i == 5) {
                            ex.setReferee5(score.getScore().toString());
                        } else if (i == 6) {
                            ex.setReferee6(score.getScore().toString());
                        } else if (i == 7) {
                            ex.setReferee7(score.getScore().toString());
                        } else if (i == 8) {
                            ex.setReferee8(score.getScore().toString());
                        } else if (i == 9) {
                            ex.setReferee9(score.getScore().toString());
                        } else if (i == 10) {
                            ex.setReferee10(score.getScore().toString());
                        }
                    }

                    List<ApplyScoreEntity> caipanzhang = socres.stream().filter(t -> "裁判长".equals(t.getType())).collect(Collectors.toList());
                    if (caipanzhang.size() > 0) {
                        ApplyScoreEntity score = caipanzhang.get(0);
                        ex.setScore(score.getScore().toString());
                        ex.setCaiPanZhangJianFen(score.getReduceScore().toString());
                        ex.setSightScore(score.getSightScore() == null ? "0.00" : score.getSightScore().toString());
                    }
                }
                results.add(ex);
            }
        }
        // 排序
        results = results.stream().sorted((o2, o1) -> {
            return (StrUtil.isBlank(o1.getScore()) ? BigDecimal.ZERO : new BigDecimal(o1.getScore()))
                    .compareTo((StrUtil.isBlank(o2.getScore()) ? BigDecimal.ZERO : new BigDecimal(o2.getScore())));
        }).collect(Collectors.toList());
        // 排名
        BigDecimal nowScore = BigDecimal.ZERO;
        int sort = 1;
        for (int i = 0; i < results.size(); i++) {
            ScoreTeamLaLaCaoExport data = results.get(i);
            if (i == 0) {
                nowScore = StrUtil.isBlank(data.getScore()) ? BigDecimal.ZERO : new BigDecimal(data.getScore());
                sort = 1;
                data.setScoreSort("第"+sort+"名");
            } else {
                BigDecimal myScore = StrUtil.isBlank(data.getScore()) ? BigDecimal.ZERO : new BigDecimal(data.getScore());
                if (myScore.compareTo(nowScore) == 0) {
                    data.setScoreSort("第"+sort+"名");
                } else {
                    sort++;
                    nowScore = myScore;
                    data.setScoreSort("第"+sort+"名");
                }
            }
        }
        // 加入不需要排名的数据
        results.addAll(noNeedSortResult);
        ExcelUtils.writeExcel(response,
                results,"队伍成绩单-啦啦操舞项目",
                "数据", ScoreTeamLaLaCaoExport.class);
    }



    @ApiOperation(value = "teamAthlete")
    @GetMapping("/teamAthlete")
    public void teamAthlete(String competitionId, String projectId , String type, String group,
                                 HttpServletResponse response) throws Exception {
        if (StrUtil.isBlank(competitionId) || StrUtil.isBlank(competitionId) || StrUtil.isBlank(competitionId) || StrUtil.isBlank(competitionId)) {
            throw new BusinessException("查询条件缺失");
        }
        // 基础数据
        List<ApplyProjectEntity> datas = applyProjectService.list(new QueryWrapper<ApplyProjectEntity>()
                .eq("competitionId", competitionId)
                .eq("projectId", projectId)
                .eq("type", type)
                .eq("groups", group)
                .orderByDesc("sort"));
        List<ScoreAthleteExport> results = new ArrayList<>();
        List<ScoreAthleteExport> noNeedSortResult = new ArrayList<>();
        for (ApplyProjectEntity data : datas) {
            ScoreAthleteExport ex = new ScoreAthleteExport();
            ApplyProjectEntity applyProject = applyService.getApplyProjectInfo(data.getId().toString());
            ApplyEntity apply = applyService.getApplyInfo(applyProject.getApplyId());
            CompetitionOrderEntity order = competitionOrderService.getById(data.getOrderId());
            if (order != null) {
                ex.setOrder(order.getTitle());
                ex.setTime(DateUtil.format(order.getStartTime(), "yyyy-MM-dd HH:mm:ss"));
            }
            ex.setTeam(apply.getTeamName());
            List<TeamPerson> coachs = apply.getCoachs();
            String coachNames = ArrayUtil.join(coachs.stream().map(TeamPerson::getName).toArray(), ", ");
            List<TeamPerson> leaders = apply.getLeaders();
            String leaderNames = ArrayUtil.join(leaders.stream().map(TeamPerson::getName).toArray(), ", ");
            ex.setLeader(leaderNames);
            ex.setCoach(coachNames);
            ex.setProject(applyProject.getProjectName());
            ex.setType(applyProject.getType());
            ex.setGroups(applyProject.getGroups());
            ex.setAthlete(ArrayUtil.join(applyProject.getAthletes().stream().map(TeamPerson::getName).toArray(), ", "));
            ex.setIdCard(ArrayUtil.join(applyProject.getAthletes().stream().map(TeamPerson::getIdCard).toArray(), ", "));
            ex.setCompetition(apply.getCompetitionName());
            ex.setStatus(applyProject.getStatus());
            if (!"打分结束".equals(ex.getStatus())) {
                noNeedSortResult.add(ex);
            } else {
                List<ApplyScoreEntity> socres = applyScoreService.list(new QueryWrapper<ApplyScoreEntity>()
                        .eq("orderId", data.getOrderId())
                        .eq("applyProjectId", applyProject.getId())
                        .eq("type", "裁判长")
                        .eq("status", "已打分")
                        .orderByDesc("sort"));
                if (socres.size() > 0) {
                    ApplyScoreEntity score = socres.get(0);
                    if (score != null) {
                        ex.setScore(score.getScore().toString());
                    }
                }
                results.add(ex);
            }
        }
        // 排序
        results = results.stream().sorted((o2, o1) -> {
            return (StrUtil.isBlank(o1.getScore()) ? BigDecimal.ZERO : new BigDecimal(o1.getScore()))
                    .compareTo((StrUtil.isBlank(o2.getScore()) ? BigDecimal.ZERO : new BigDecimal(o2.getScore())));
        }).collect(Collectors.toList());
        // 排名
        BigDecimal nowScore = BigDecimal.ZERO;
        int sort = 1;
        for (int i = 0; i < results.size(); i++) {
            ScoreAthleteExport data = results.get(i);
            if (i == 0) {
                nowScore = StrUtil.isBlank(data.getScore()) ? BigDecimal.ZERO : new BigDecimal(data.getScore());
                sort = 1;
                data.setScoreSort("第"+sort+"名");
            } else {
                BigDecimal myScore = StrUtil.isBlank(data.getScore()) ? BigDecimal.ZERO : new BigDecimal(data.getScore());
                if (myScore.compareTo(nowScore) == 0) {
                    data.setScoreSort("第"+sort+"名");
                } else {
                    sort++;
                    nowScore = myScore;
                    data.setScoreSort("第"+sort+"名");
                }
            }
        }
        // 加入不需要排名的数据
        results.addAll(noNeedSortResult);

        List<ScoreAthleteExport> lastResult = new ArrayList<>();
        // 运动员数据复制
        for (ScoreAthleteExport result : results) {
            String[] athletes = result.getAthlete().split(",");
            String[] idCards = result.getIdCard().split(",");
            for (int i = 0; i < athletes.length; i++) {
                String athlete = athletes[i];
                String idCard = idCards[i];
                ScoreAthleteExport scoreAthlete = (ScoreAthleteExport) result.clone();
                scoreAthlete.setAthlete(athlete);
                scoreAthlete.setIdCard(idCard);
                lastResult.add(scoreAthlete);
            }
        }

        ExcelUtils.writeExcel(response,
                lastResult,"队伍成绩单-运动员表成绩单",
                "数据", ScoreAthleteExport.class);
    }

}
